package demo;
//可重入锁
class Count{
    public int count = 0;

    public  void add(){
        synchronized (this){
            count++;
        }
    }
    public int getCount(){
        return this.count;
    }
}
public class Test6 {
    public static void main(String[] args) throws InterruptedException {
        Count count = new Count();
        Thread thread = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (count) {
                    synchronized (count) {
                        count.add();
                    }
                }
            }
        });
        thread.start();
        thread.join();

        System.out.println(count.getCount());
    }


}
